package pe.com.hatunsol.hatun_android;

import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.util.Log;
import android.widget.ListView;
import android.widget.Toast;

import java.util.List;

import pe.com.hatunsol.hatun_android.adapter.DetalleAdapter;
import pe.com.hatunsol.hatun_android.dao.DataBaseHelper;
import pe.com.hatunsol.hatun_android.dao.DetalleVentaDAO;
import pe.com.hatunsol.hatun_android.entity.DetalleVenta;
import pe.com.hatunsol.hatun_android.entity.Venta;

/**
 * Created by vladimir.flores on 12/03/2015.
 */
public class ListarDetalleVenta extends ActionBarActivity {

    private ListView lvDetalle;
    private List<DetalleVenta> lsdetalleventa = null;
    private DetalleAdapter MdetalleAdapter = null;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.listado_detalle);

        lvDetalle      = (ListView)findViewById(R.id.lvDetalle);
        int      cod    = getIntent().getExtras().getInt("N1");
        //
        try{
            DataBaseHelper dataBaseHelper = new DataBaseHelper(ListarDetalleVenta.this);
            dataBaseHelper.createDataBase();
            dataBaseHelper.openDataBase();
        }catch (Exception ex){
            Toast.makeText(ListarDetalleVenta.this, "No se pudo abrir la BD", Toast.LENGTH_SHORT).show();
        }

        DetalleVentaDAO detalle = new DetalleVentaDAO();
        lsdetalleventa = detalle.detalleventa(cod);

        /*int num = lsdetalleventa.size();
        Log.d("cant es:", String.valueOf(num));*/

        //Toast.makeText(ListarDetalleVenta.this, "Cod Venta: " + cod, Toast.LENGTH_SHORT).show();

        MdetalleAdapter = new DetalleAdapter(ListarDetalleVenta.this,0,lsdetalleventa);
        lvDetalle.setAdapter(MdetalleAdapter);



    }


}
